package com.renbang.action.common;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.renbang.model.common.AjaxResult;
import com.renbang.model.common.Page;
import com.renbang.model.finance.Dictionary;
import com.renbang.service.finance.DictionaryService;
import com.renbang.action.BaseAction;
/**
 * 该代码由程序生成
 */
@Controller
@RequestMapping(value = "common/Dictionary")
public class DictionaryAction  extends BaseAction<Dictionary>{
	@Autowired
	DictionaryService dictionaryService;
	
	@RequestMapping(value = "/showSelect")
	public  @ResponseBody AjaxResult showSelect(HttpServletRequest request,Dictionary obj) {
		if(obj.getDicType().equals("orgType")){
			obj.setDicType("机构类型");
		}else if(obj.getDicType().equals("area")){
			obj.setDicType("所在区域");
		}
		return new AjaxResult(AjaxResult.STATUS_OK, "数据加载成功", dictionaryService.findByModel(obj),0);
	}
	
	//打开新增或修改页面
	@RequestMapping(value = "/editForm")
	public String editForm(Integer id, HttpServletRequest request) {
		Dictionary dictionary;
		if (id != null) {
			dictionary = dictionaryService.findById(id);
			request.setAttribute("obj", dictionary);
		}
		return "user/finance/Dictionary-form";
	}
	@RequestMapping(value = "/addOrModify")
	public  @ResponseBody AjaxResult insertOrUpdata(HttpServletRequest request,
	Dictionary dictionary) {
		if(dictionary.getId()!=null){
			int i = dictionaryService.modify(dictionary);
			if (i > 0)
				return new AjaxResult(AjaxResult.STATUS_OK, "修改成功");
			else
				return new AjaxResult(AjaxResult.STATUS_OK, "修改失败");
	} else {
		 int i = dictionaryService.add(dictionary);
		 if (i > 0)
		 	return new AjaxResult(AjaxResult.STATUS_OK, "增加成功");
		 else
			return new AjaxResult(AjaxResult.STATUS_OK, "增加失败");
	}
		
	}
	
}
